<template>
	<view>
		<view class="top cflex">
			<view class="top_item" :class="type==1?'active':''" @tap="change(1)">
				全部
			</view>
			<view class="top_item" :class="type==2?'active':''" @tap="change(2)">
				财务审核中
			</view>
			<view class="top_item" :class="type==3?'active':''" @tap="change(3)">
				待发货
			</view>
			<view class="top_item" :class="type==4?'active':''" @tap="change(4)">
				已发货
			</view>
			<view class="top_item" :class="type==5?'active':''" @tap="change(5)">
				已完成
			</view>
		</view>

     <scroll-view scroll-y="true" style="height: 100%;width: 100%;" @scroll="loadMores"  :refresher-threshold="100">
		<view v-for="(item,index) in list">
			<view class="item flex">
				<view class="item_top cflex">
					<view class="orderNum">
						订单编号：{{item.order_num}}
					</view>
					<view class="status_text">
						{{item.status_text}}
					</view>
				</view>
				<view class="item_mid cflex" @click="detail(item)">
					<image :src="item.images" mode=""></image>
					<view class="goods">
						<view class="goodsName">
							{{item.name}}
						</view>
						<view class="label">
							{{item.type_name}}
						</view>
						<view class="price">
							出厂价：{{item.factory_price}}元
						</view>
						<view class="count">
							购买件数：{{item.num}}件
						</view>
					</view>
				</view>
				<view class="item_bottom cflex ">
					<view class="button1 " @tap="call">
						联系客服
					</view>
					<view class="button3 " v-if="item.status_text=='已发货'" @click="tianxie(item)">
						填写物流
					</view>
					<view class="button3 " v-if="item.status_text=='已发货'">
						查看物流
					</view>
					<view class="button3 " v-if="item.status_text=='已发货'" :data-order_id="item.order_id" @tap="takeOrder">
						确认收货
					</view>
					<view class="button3 " v-if="item.status_text=='待发货'" :data-order_id="item.order_id" @tap="sort">
						提醒发货
					</view>
					<view class="button3 " v-if="item.status_text=='待评价'" :data-order_id="item.order_id" @tap="">
						去评价
					</view>
					<view class="button2 " :data-order_id="item.order_id" @tap="todetail(item)">
						查看订单
					</view>
				</view>
			</view>
		</view>
	</scroll-view>
		
		
		<view class="black_moban" v-show="shows"></view>
		<view class="wuliu_top" v-show="shows">
			<view class="title">填写物流</view>
			<view class="title_1">
				<picker @change="bindPickerChange" :value="index" :range="array">
					<view class="uni-input">{{array[index]}}</view>
				</picker>
			</view>
			<view class="title_2">
				<input v-model="wuliu_no" placeholder="请输入物流单号" class="index-title" />
			</view>
			<view class="center">
				<view class="left" @click="close()">取消</view>
				<view class="right" @click="submits()">确认</view>
			</view>
		</view>

		<view class="zz" v-if="zz==true"></view>
		<view class="callModel" v-if="callModel==true">
			<view class="callModel_tit">
				客服电话
			</view>
			<view class="callModel_Text">
				{{DefaultPhone}}
			</view>
			<view class="callModel_bottom cflex">
				<view class="cancel" @tap="callModelFalse">
					取消
				</view>
				<view class="tocall" @tap="tocall">
					呼叫
				</view>
			</view>
		</view>
		<!-- 
	 <view class="item_bottom cflex " v-if="item.status_text=='财务审核中'||item.status_text=='已完成'">
	 	<view class="button1 ">
	 		联系客服
	 	</view>
	 	<view class="button2 ">
	 		查看订单
	 	</view>
	 </view>
	 <view class="item_bottom cflex " v-if="item.status_text=='待发货'">
	 	<view class="button1 ">
	 		联系客服
	 	</view>
	 	<view class="button3 ">
	 		提醒发货
	 	</view>
	 	<view class="button2 ">
	 		查看订单
	 	</view>
	 </view>
	 <view class="item_bottom cflex " v-if="item.status_text=='已发货'">
	 	<view class="button1 ">
	 		联系客服
	 	</view>
	 	<view class="button3 ">
	 		填写物流
	 	</view>
	 	<view class="button3 ">
	 		确认收货
	 	</view>
	 	<view class="button2 ">
	 		查看订单
	 	</view>
	 </view>
	 <view class="item_bottom cflex " v-if="item.status_text=='待评价'">
	 	<view class="button1 ">
	 		联系客服
	 	</view>
	 	<view class="button3 ">
	 		去评价
	 	</view>
	 	<view class="button2 ">
	 		查看订单
	 	</view>
	 </view>
	 -->

	</view>
</template>

<script>
	import {
		ajax
	} from '../../ajax.js';
	export default {
		data() {
			return {
				zz: false,
				callModel: false,
				type: 1,
			    index: 0,
				wuliu_no:'',
				items:'',
				DefaultPhone: '',
				firstNum: 1,
			    array: ['请选择物流公司','中通快递', '圆通快递', '顺丰快递', '申通快递'],
				num: 10,
				last_page:'',
				list: [
					{
						images: [" "],
					}
				],
				shows:false,
				scrollTop: 0,
			}
		},
		onLoad(e) {
			let that = this
			that.type = e.type
			that.getlist()
			that.getDefaultPhone()

		},
		onPullDownRefresh() {
			this.loadMores()
		},
		onReachBottom(e) {
			this.loadMores();
		},
		methods: {
			loadMores(){   
				let that = this
				let status = that.type
				let num = that.num
				let token = uni.getStorageSync('token')
				that.firstNum=that.firstNum+1
				if(that.firstNum>that.last_page){
					uni.showToast({
						title: "没有更多数据",
						icon:'none'
					})
					return
				}
				//that.list=[]
				ajax({
					url: 'order/myOrder',
					data: {
						token: token,
						firstNum: that.firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						//that.list = res.data.data.data
						res.data.data.data.slice(0).forEach(e => {
							  that.list.push(e);
							});
						that.last_page=res.data.data.last_page
						
					},
					error: function() {
				
					}
				});
			},
			tianxie(item){
				let that=this
				that.items=item
				that.shows=true
			},
			close(){
			  this.shows=false
			},
			submits(){
				let that =this
				if(that.wuliu_no==''){
					uni.showToast({
						title: "请输入物流单号",
						icon:'none'
					})
					return
				}
				if(that.index==0){
					uni.showToast({
						title: "请选择物流公司",
						icon:'none'
					})
					return
				}
				ajax({
					url: 'order/addExpress',
					data: {
				        order_id:that.items.order_id,
						express:that.array[that.index],
						express_no:that.wuliu_no
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						if(res.data.code==1){
							that.shows=false
							uni.showToast({
								title:'填写成功',
								icon:'none'
							})
						}else{
							uni.showToast({
								title: res.data.msg,
								icon:'none'
							})
							
						}
						
					},
					error: function() {
				
					}
				});
			},
			bindPickerChange: function(e) {
			   console.log('picker发送选择改变，携带值为', e.target.value)
			   this.index = e.target.value
		     },
			change(e) {
				let that = this
				that.type = e
				that.getlist()
			},
			detail(item){
				uni.navigateTo({
					url:'/pages/detailPro/detailPro?id='+item.good_id
				})
			},
			callModelFalse() {
				let that = this
				that.callModel = false
				that.zz = false
			},
			tocall() {
				let that = this
				let phone = that.DefaultPhone
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
				that.zz = false
				that.callModel = false
			},
			call() {
				let that = this
				that.zz = true
				that.callModel = true
			},
			getDefaultPhone() {
				let that = this
				ajax({
					url: 'order/getDefaultPhone',
					data: {

					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data)
						 that.DefaultPhone = res.data.data
					},
					error: function() {

					}
				});
			},
			getlist() {
				let that = this
				let status = that.type
				let firstNum = that.firstNum
				let num = that.num
				let token = uni.getStorageSync('token')
				that.list=[]
				ajax({
					url: 'order/myOrder',
					data: {
						token: token,
						firstNum: firstNum,
						num: num,
						status: status
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						console.log("token", res.data.data.data)
						//res.data.data.data[0].status_text='已发货'
						that.list = res.data.data.data
						that.last_page=res.data.data.last_page
						
					},
					error: function() {

					}
				});
			},
			sort(e) {
				let that = this
				let order_id = e
				console.log(order_id)
				ajax({
					url: 'order/sort',
					data: {
						//token: uni.getStorageSync('token'),
						order_id: order_id
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						uni.showToast({
							title: "提醒发货成功"
						})
					},
					error: function() {

					}
				});
			},
			takeOrder(e) {
				let that = this
				let order_id = e
				console.log(order_id)
				ajax({
					url: 'order/takeOrder',
					data: {
						token: uni.getStorageSync('token'),
						order_id: order_id
					},
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					success: function(res) {
						uni.showToast({
							title: "确认收货成功"
						})
					},
					error: function() {

					}
				});
			},
			todetail(item) {
				let that = this
				let order_id = item.order_id
				console.log(order_id)
				uni.navigateTo({
					url: '/pages/order/order_info?id='+order_id
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.zz {
		width: 750rpx;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: absolute;
		top: 0;
	}
	.black_moban{
		width: 750rpx;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: absolute;
		top: 0;
	}
	.wuliu_top{
		width: 620rpx;
		height: 347rpx;
		background-color: #FFFFFF;
		position: absolute;
		top: 401rpx;
		left: 65rpx;
		.center{
			width: 100%;
			overflow: hidden;
			margin: 0rpx auto;
			.left{
				width: 50%;
				line-height: 88rpx;
				height: 88rpx;
				text-align: center;
				color: #333;
				background: #fff;
				float: left;
				border-bottom-left-radius:20rpx
			}
			.right{
				width: 50%;
				line-height: 88rpx;
				height: 88rpx;
				text-align: center;
				color: #FFFFFF;
				background: #FF7427;
				float: left;
				border-bottom-right-radius:20rpx
			}
		}
		.title{
			font-size: 30rpx;
			padding: 20rpx 0rpx 20rpx 0rpx;
			text-align: center;
		}
		.title_1{
			text-align: center;
			font-size: 30rpx;
			width: 90%;
			height: 48rpx;
			line-height: 48rpx;
			background: url(../../static/clq-image/xiangxia.png) no-repeat right;
			background-size: 20rpx;
			background-position:428rpx 16rpx;
			border: 2rpx solid #999;
			border-radius: 8rpx;
			margin: 28rpx auto;
			
		}
		.index-title{
			width:88%;
			margin: 28rpx auto;
			height: 48rpx;
			line-height: 48rpx;
			border-radius: 8rpx;
			border: 2rpx solid #999;
			padding-left:2%;
		}
	}

	.callModel {
		width: 620rpx;
		height: 276rpx;
		background-color: #FFFFFF;
		position: absolute;
		top: 471rpx;
		left: 65rpx;
		border-radius: 20rpx;
	}

	.callModel_tit {
		text-align: center;
		font-size: 28rpx;
		color: #333333;
		margin-top: 18rpx;
	}

	.callModel_Text {
		text-align: center;
		font-size: 30rpx;
		color: #FF7427;
		margin-top: 60rpx;
	}

	.callModel_bottom>view {
		width: 50%;
		text-align: center;
		height: 88rpx;
		margin-top: 32rpx;
		line-height: 88rpx;
		font-size: 28rpx;
	}

	.cancel {
		background-color: #F7F7F7;
		border-bottom-left-radius: 20rpx;
	}

	.tocall {
		color: #FFFFFF;
		background-color: #FF7427;
		border-bottom-right-radius: 20rpx;
	}

	.top {
		width: 95%;
		margin: 0 auto;
		justify-content: space-between;
		/**margin-bottom: 44rpx;**/
	}

	.active {
		color: #FF7427;
		border-bottom: 1px solid #FF7427;
		padding-bottom: 5rpx;
	}

	.top_item {
		font-size: 28rpx;
	}

	.item {
		width: 712rpx;
		height: 333rpx;
		background-color: #FFFFFF;
		margin: 22rpx auto;
	}

	.item_top {
		justify-content: space-between;
		width: 95%;
		margin: 0 auto;
		padding-top: 23rpx;
	}

	.orderNum {
		font-size: 28rpx;
		color: #333333;
	}

	.status_text {
		font-size: 24rpx;
		color: #FF7427;
	}

	.item_mid {
		width: 95%;
		margin: 0 auto;
		margin-top: 20rpx;
	}

	.item_mid>image {
		width: 169rpx;
		height: 169rpx;
		background-color: #000000;
		border-radius: 10rpx;
	}

	.goods {
		margin-left: 29rpx;

	}

	.goodsName {
		font-size: 28rpx;
		color: #333333;
	}

	.label {
		font-size: 24rpx;
		color: #555555;
		margin-top: 10rpx;
	}

	.price {
		font-size: 24rpx;
		color: #D50000;
		margin-top: 15rpx;
	}

	.count {
		font-size: 24rpx;
		color: #555555;
		margin-top: 10rpx;
	}

	.item_bottom {
		justify-content: flex-end;
		margin-top: 20rpx;
	}

	.item_bottom>view {
		margin-right: 20rpx;
		width: 160rpx;
		height: 48rpx;
		border-radius: 100rpx;
		font-size: 28rpx;
		line-height: 48rpx;
		text-align: center;
	}

	/* 联系客服 */
	.button1 {
		border: 1px solid #999999;
		color: #999999;
	}

	/* 查看订单 */
	.button2 {
		background-color: #FF7427;
		color: #FFFFFF;
	}

	/* 提醒发货 填写物流 查看物流 去评价*/
	.button3 {
		border: 1px solid #FF7427;
		color: #FF7427;
	}
</style>
